package com.etc.controller;

import java.util.ArrayList;

import com.etc.entity.Counter;
import com.etc.service.CounterService;

public class LoginController {

	CounterService counterService = new CounterService();
	
	//判断账号密码是否正确
	//获取客户端返回的账号密码进行匹配，匹配成功表示存在此账户
	public Counter login(String userId, String password) {
		Counter counter = null;
		ArrayList<Counter> counters = counterService.findAllCounter();//获取系统所有的账户
		for (Counter c : counters) {
			if(c.getLoginId().equals(userId) && c.getPassword().equals(password)) { //存在就返回此账号
				counter = c;
				break;
			}
		}
		//如果上面遍历没有找到，就会返回Null
		return counter;
	}
	
	//判断账号是否已经被注册
	public boolean registerConfrim(String userId) {
		boolean confirm = false;
		ArrayList<Counter> counters = counterService.findAllCounter();//获取系统所有的账户
		for (Counter c : counters) {
			if(c.getLoginId().equals(userId) ) { //有没有这个账户
				confirm = true;
				break;
			}
		}
		//返回true表示存在此账户，就不能注册，
		//返回false表示不存在此账户，就可以注册
		return confirm;
	}
}
